package com.wsd.action;


import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.wsd.bean.Articles;
import com.wsd.bean.Category;
import com.wsd.bean.Link;
import com.wsd.bean.Products;
import com.wsd.service.ArticleService;
import com.wsd.service.CategoryService;
import com.wsd.service.LinkService;
import com.wsd.service.ProductService;

/**
 * @author TuZiJun
 *
 */
public class IndexAction extends ActionSupport {
	private CategoryService categoryService = null;
	private ProductService productService = null;
	private ArticleService articleService = null;
	private LinkService linkService = null;
	public void setCategoryService(CategoryService categoryService) {
		this.categoryService = categoryService;
	}
	public void setProductService(ProductService productService) {
		this.productService = productService;
	}
	public String index() {
		HttpServletRequest request = ServletActionContext.getRequest();
		List<Category> categorys = categoryService.findByLevel(1);
		List<Products> recommendProducts = productService.rankByModel((short)1, 4);
		List<Products> hotProducts = productService.rankByModel((short)2, 4);
		List<Products> newProducts = productService.rankByModel((short)3, 4);
		List<Articles> companynews = articleService.findByModel(0, 5, 1);
		List<Articles> industrynews = articleService.findByModel(0, 5, 2);
		List<Link> links = linkService.findAll(0, 5);
		request.getSession().setAttribute("categorys", categorys);
		request.getSession().setAttribute("links", links);
		request.setAttribute("recommendProducts", recommendProducts);
		request.setAttribute("hotProducts", hotProducts);
		request.setAttribute("newProducts", newProducts);
		request.setAttribute("companynews", companynews);
		request.setAttribute("industrynews", industrynews);
		return SUCCESS;
	}
	
	public String wsd () {
		return SUCCESS;
	}
	public void setArticleService(ArticleService articleService) {
		this.articleService = articleService;
	}
	public void setLinkService(LinkService linkService) {
		this.linkService = linkService;
	}
}